<?php
ob_start();
      #call all includes below
    require_once('cls_config.php');  //data base connections and sessions are stored also
    include_once 'miscellaneous.php';
    connection::start_session();
    include_once 'cls_forms.php';
    include_once 'cls_student.php';
    include_once 'cls_admin.php';
?>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en">

<head>

<title>SSC</title>

    <style type="text/css">
    @media print{

        body{
           width: 8.5in;
            height: 11in; 
            font-family : "Arial", Verdana, sans-serif;
            line-height: 1em;
            font-size: 12px;
            font-weight:bold;
        }
        p{
             font-family : "Arial", Verdana, sans-serif;
            line-height: 1em;
            font-size: 12px;
               font-weight:bold;
            
        }
        table.listings tr td,input{
             font-family :"Arial", Verdana, sans-serif;
            line-height: 0.89em;
            font-size: 12px;
            padding: 0;
               font-weight:bold;
        }
        table.listings tr th{
             font-family :  "Arial", Verdana, sans-serif;
            line-height: 0.89em;
            font-size: 12px;
           border-bottom: black solid thin;
            border-top: black solid thin;
            border-left: none;
            border-right: none;
               font-weight:bold;
        }
        em{
            font-weight: bolder;
        }
    }
    </style>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="prototype.js"></script>
    <script type="text/javascript" src="script.js"></script>
     <script type="text/javascript" src="ssc_reg_sis.js"></script>
</head>
 <?php 
    
switch($_POST['submit']){
       case 'PRINT EVALUATION':
       ?>
       <body onload="">
       <?php
                 $student=new general_student($_POST['student_id']);
                              if($student->check_valid_user()){
                                #check if payment is made;returns array of options(count,yr_lvl, semester)
                                #assess the allowed subjects to be enrolled  based from prerequisites                   
                                     $grades = $student->get_evaluation($_POST['yr_lvl'],$_POST['semester']);
                                      $profile= $student->get_profile();
                                      registar_forms::show_evaluation_form_print($grades,$profile);                                   
                              }else{
                                  die("<p class='warnings'>You are not enrolled</p>");
                              }
            break;     
       
       
        case 'Confirm and Dowload Receipt':
        ?>
       <body onload="download_print_receipt();">
       <?php
                #this function will get all values of post and insert to table admission
                $data = admin_functions::admission_processing($_POST);
                //admin_functions::download_receipt($data);
                admission_forms::admission_receipt_print($data);
                break;
            
       case 'PRINT COG':
        ?>
         <body onload="repage_cog();">
         <?php 
  #new student to enroll, it gets the grades to generate a draft copy of COG
  #check first whether a draft copy is requested or not
  if($_POST['draft']=="YES"){
      $student = new general_student($_SESSION['profile_id']);
  }else{
        $student=new general_student($_POST['student_id']);
  }
             
                    if($student->check_valid_user()){
                        $grades  = $student->get_cog($_POST['yr_lvl'],$_POST['semester']);
                        $profile = $student->get_profile();
                        
                        $excel = new download_excel("reports/certificate_of_grades.xls");
                        
                        #start the download
                        #define the constant body
                        $body_1 = "This is to certify that ";
                        $body_1.= strtoupper($profile[0]['name']);
                        $body_1.=" of ";
                        $body_1.= $profile[0]['address'].", ";
                          $excel->set_cell_value("C12",$body_1);                         
                        
                        $body_2.= " is officially enrolled this ";
                        $body_2.= $_POST['semester']=1?"FIRST ":"SECOND ";
                        $body_2.= "semester w/ the degree of ";
                        $body_2.=$profile[0]['degree_name'].".";
                        
                           $excel->set_cell_value("A13",$body_2);
                                                      
                        $body_3.= $profile[0]['gender']=="M"?"He":"She";
                        $body_3.=" has the following ratings specified";
                        
                            $excel->set_cell_value("C14",$body_3);                              
                              $row=17;
                               $units=0;//used as total for units
                                foreach($grades as $to_show){
                                   $excel->set_column_row_value(1,$row,$to_show['subj_code']);
                                   $excel->set_column_row_value(3,$row,$to_show['description']);
                                    $excel->set_column_row_value(6,$row,$to_show['units']);
                                    $excel->set_column_row_value(7,$row,$to_show['grade_1']);
                                    $excel->set_column_row_value(7,$row,$to_show['status']);
                                    $units = $units + $to_show['units'];
                                    $row++;
                                }
                                $excel->set_column_row_value(2,($row+2),"Total units");
                                 $excel->set_column_row_value(6,($row+2),$units);

                              
                        $body_4 = "This certification is issued this".date('jS \d\a\y \o\f F Y')." upon request of ";                        
                        $excel->set_cell_value("C35",$body_4);
                         $body_5 = $_POST['naghagad']."for ".$_POST['purpose'];    
                        $excel->set_cell_value("A36",$body_5);
                        
                        $excel->force_download(strtoupper($profile[0]['name']).$_POST['yr_lvl']."_".$_POST['semester']);
                        
                       /* ?>
                        <!-- show the letter head-->                  
                        
                                <table align="center" style="margin: 0.5in 0.5in 0.5in 0.5in;">
                                    <tr>
                                        <td>
                                 
                                <img src="images/ssc_logo.jpg" height="100px"  style="position: absolute;margin: 0.5in 0 0 0.5in;" align="left"/> 
                                         
                                <p align="center" style="text-align: center;">
                                Republic of the Philippines<br>
                                SORSOGON STATE COLLEGE<br>
                                SORSOGON CAMPUS<br>
                                Sorsogon City<br>
                                Tel. No. 056-211-1869 Fax No. 056-211-1845<br>
                                Office of the College of Registrar<br>
                                </p>
                                      
                 


                                <center>
                                    <h1>CERTIFICATION</h1>
                                </center>

                                <p style="margin-left: 0.5in;">TO WHOM IT MAY CONCERN:</p>
                            

                                                <p style="text-indent: 100px; margin: 0in 0.5in 0in 0.5in;text-align: justify;" >
                                                This is to cerftify that, <em style="font-weight: bolder;text-decoration: underline;"><?php echo strtoupper($profile[0]['name']);?></em> of <?php echo $profile[0]['address'];?>
                                                is officially enrolled this 
                                                <?php echo $_POST['semester']=1?"FIRST":"SECOND ";
                                                echo " semester A.Y. 2011-2012";?> with the degree of <?php echo $profile[0]['degree_name'];?>.
                                                </p>
                                                <p style="text-indent: 100px; margin: 0in 0.5in 0in 0.5in;text-align: justify;" >
                                                <?php echo $profile[0]['gender']=="M"?"He":"She";?> has the following ratings specified below.
                                                </p>
                                                <br>
                                                
                                          
      
                                    <?php
                                #show the content subjects                                            
                            registar_forms::draft_cog($grades,$profile,$_POST['yr_lvl'],$_POST['semester']);
                            ?>
                             <p style="text-indent: 100px; margin: 0in 0.5in 0in 0.5in;text-align: justify;" >
                                            This certification is issued this <?php   echo date('jS \d\a\y \o\f F Y'); ?> upon request of <?php echo $_POST['naghagad'];?> for <?php echo $_POST['purpose'];?>.
                                           </p>


                                            <p style="text-align: center; margin: 80px 0 0 300px;">
                                                MARIA LOURDES G. BARROZO <br>
                                                College Registrar
                                            </p>

                                        <p style="font-size: 8px;margin-left: 1in;">
                                        Not valid w/o<br>
                                        College Dry Seal<br>
                                        MLGB/hdd/tdc
                                        </p>
                                            </td>
                                        </tr>
                                    </table>
                          
                               <?php     */
                    }else{
                        echo "you are not a valid user";
                    }
                        unset($student);

            break;
           
            case 'Process Subjects': 
            ?>
             <body>
            <?php 
            ######################
             security::record_logs($_SESSION['username'],"Process Subjects","A Post Event","Evaluating Student Id: ".$_POST['student_id']);
            #######################
            
            #new student to enroll, it assess subjects by verifying grades first
            $student=new general_student($_POST['student_id']);
            if($student->check_valid_user()){
                
                #get the profile
                    $profile= $student->get_profile();
 
                #assess the allowed subjects to be enrolled  based from prerequisites and also update the enroll table for yrlvls, smemster etc
                if(isset($_POST['add_allow'])){
                    $subjects= $student->assess_added_subjects($_POST);
                }else{
                     $subjects = $student->get_assessed($_POST['semester'],$profile,$_POST['yr_lvl']);
                }
               
                if(is_array($subjects)){
                     
                    #get the fees
                     $assessment=$student->get_babayran($_POST['semester']);
                     
                    #insert into a student profile in cashier by checking first if a student id exists
                     admin_functions::insert_cashier_profile($_POST['student_id'],$profile);
                     
                    #get the current year levle
                     // $yr_lvl = specific_student::get_year_specific_level($profile[0]['course'],$profile[0]['major'],$_POST['semester'],$_POST['student_id']);
                     $yr_lvl=$_POST['yr_lvl'];
                      
                    #show subjects and profile in form
                    registar_forms::assessed_subjects($subjects,$profile,$assessment,$yr_lvl,$_POST['semester'],$_POST['assessor']); 
                }else{
                    #show form adding, dropping etc
                     if (ob_get_contents()!='') {
                        ob_clean();
                    }
                    header("location:main.php?page=registrar&spec=addsubjects&action=ask&studid=".$_POST['student_id']."&yrlvl=".$_POST['yr_lvl']."&sem=".$_POST['semester']);
                }
                
            }else{
                echo "<script type'text/javascript'>alert('No records found for id: {$_POST['student_id']}');window.close();</script>";
            }
             unset($student);
            break;
            
           case 'PRINT RECEIPT':
                           #this will get the payables from collectibles table
                           $data = admin_functions::get_cashier_payments($_POST['student_id'],$_POST['assess_no']);
                           #this will show the requested form
                           cashier_forms::babayaran($data,$_POST['student_id'],$_POST['assess_no']);
                break; 
           
            case 'Process Payment':
            ?>
            <body></body>
            <?php
                    #this will get the payables from collectibles table
                       $data = admin_functions::get_cashier_payments($_POST['student_id'],$_POST['assess_no']);
                       #this will show the requested form
                       $name = sql_functions::select_query("name from cash_profile where student_id='".$_POST['student_id']."'","cashier");
                       $name = sql_functions::fetch_to_array($name);
                        cashier_forms::babayaran($data,$name[0]['name'],$_POST['student_id'],$_POST['assess_no']);
                break;    
}
 ?>

 </body>
 

</html>

 